/**
 * 七种武器加载动效：显示与武器类型相关的加载动画
 */

// 武器类型和名称映射
const weaponTypes = ['hammer', 'bow', 'spear', 'ladder', 'awl', 'blade', 'mirror'];
const weaponNames = ['问题之锤', '类比之弓', '定义之矛', '抽象之梯', '质疑之锥', '逻辑之刃', '视角之镜'];

/**
 * 显示武器加载动效
 * @param {Element} svg - SVG元素
 * @param {number} index - 当前武器索引
 * @param {Array} apiEndpoints - API端点数组
 */
function showLoading(svg, index, apiEndpoints) {
    // 获取当前API端点对应的武器类型
    const endpointStr = apiEndpoints[index];
    let weaponType = 'hammer'; // 默认为锤子
    
    // 从端点URL确定武器类型
    for (let i = 0; i < weaponTypes.length; i++) {
        if (endpointStr.includes(weaponTypes[i])) {
            weaponType = weaponTypes[i];
            break;
        }
    }
    
    // 根据武器类型设置不同的加载动画
    let loadingHTML = `
        <rect width="300" height="475" fill="#f0f0f0"/>
        <g class="loading-container ${weaponType}-loading">
            <circle class="loading-glow" cx="150" cy="200" r="130"/>
    `;
    
    // 基于武器类型添加特定元素
    switch(weaponType) {
        case 'hammer':
            loadingHTML += getHammerLoadingHTML();
            break;
        case 'bow':
            loadingHTML += getBowLoadingHTML();
            break;
        case 'spear':
            loadingHTML += getSpearLoadingHTML();
            break;
        case 'ladder':
            loadingHTML += getLadderLoadingHTML();
            break;
        case 'awl':
            loadingHTML += getAwlLoadingHTML();
            break;
        case 'blade':
            loadingHTML += getBladeLoadingHTML();
            break;
        case 'mirror':
            loadingHTML += getMirrorLoadingHTML();
            break;
    }
    
    // 添加加载文字
    const weaponNameIndex = weaponTypes.indexOf(weaponType);
    const displayName = weaponNameIndex >= 0 ? weaponNames[weaponNameIndex] : '思维武器';
    
    loadingHTML += `
            <text class="loading-text" x="150" y="370" text-anchor="middle">${displayName}蓄力中...</text>
        </g>
    `;
    
    svg.innerHTML = loadingHTML;
}

// 锤子加载动画HTML
function getHammerLoadingHTML() {
    return `
        <path class="weapon-icon" d="M150,220 L150,150 L120,120 L180,120 L150,150" fill="#777" stroke="#555" stroke-width="2" />
    `;
}

// 弓箭加载动画HTML
function getBowLoadingHTML() {
    return `
        <path class="weapon-icon" d="M120,150 C80,200 80,250 120,300 M120,150 C160,200 160,250 120,300" fill="none" stroke="#654321" stroke-width="4" />
        <line class="arrow" x1="120" y1="225" x2="170" y2="225" stroke="#555" stroke-width="2" />
    `;
}

// 矛加载动画HTML
function getSpearLoadingHTML() {
    return `
        <line class="weapon-icon" x1="150" y1="300" x2="150" y2="150" stroke="#654321" stroke-width="4" />
        <path class="weapon-icon" d="M140,150 L150,120 L160,150 Z" fill="#aaa" stroke="#555" stroke-width="1" />
    `;
}

// 梯子加载动画HTML
function getLadderLoadingHTML() {
    return `
        <g class="ladder-steps">
            <rect class="step" x="100" y="150" width="20" height="4" />
            <rect class="step" x="100" y="180" width="20" height="4" />
            <rect class="step" x="100" y="210" width="20" height="4" />
            <rect class="step" x="100" y="240" width="20" height="4" />
            <rect class="step" x="100" y="270" width="20" height="4" />
        </g>
        <line x1="120" y1="140" x2="120" y2="280" stroke="#654321" stroke-width="3" />
        <line x1="180" y1="140" x2="180" y2="280" stroke="#654321" stroke-width="3" />
    `;
}

// 锥子加载动画HTML
function getAwlLoadingHTML() {
    return `
        <path class="weapon-icon" d="M150,180 L130,230 L150,280 L170,230 Z" fill="#aaa" stroke="#666" stroke-width="1.5" />
        <line class="weapon-icon" x1="150" y1="180" x2="150" y2="130" stroke="#aaa" stroke-width="3" />
    `;
}

// 刀刃加载动画HTML
function getBladeLoadingHTML() {
    return `
        <g class="blade-container">
            <line class="slash" x1="110" y1="150" x2="190" y2="200" />
            <line class="slash" x1="110" y1="180" x2="190" y2="230" />
            <line class="slash" x1="110" y1="210" x2="190" y2="260" />
        </g>
        <path d="M150,150 L150,300" stroke="#654321" stroke-width="2" fill="none" />
    `;
}

// 镜子加载动画HTML
function getMirrorLoadingHTML() {
    return `
        <circle class="weapon-icon" cx="150" cy="200" r="60" fill="none" stroke="#777" stroke-width="4" />
        <div class="reflection"></div>
    `;
}
